package com.oxygen.pt.utils;

import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;

/**
 * 随机ID生成器
 */
@Component
public class RedisIdWorker {

    private static final Long BEGIN_TIMESTAMP = 1704067200L;
    private static final int COUNT_BIT = 32;

    public RedisIdWorker(StringRedisTemplate stringRedisTemplate) {
    }

    public long nextId(String keyPrefix){

        Snowflake12 gen = new Snowflake12(1);
        return gen.next();
    }

//    public long nextId(){
//        long nowSecond = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC);
//        long timeStamp = nowSecond -BEGIN_TIMESTAMP;
//
//        //生成序列号
//        //获取当前的日期 精确到天
//        String day = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
//        Long count = stringRedisTemplate.opsForValue().increment("icr:"+keyPrefix + ":" + day);
//
//        //拼接并返回
//        return timeStamp<<COUNT_BIT | count;
//    }


}
